package com.yxt.common.sort;

import java.util.Comparator;
import java.util.Map;

public class MapComparator implements Comparator<Map<String,String>> {
	private String key;
	
	public String getKey() {
		return key;
	}

	public void setKey(String key) {
		this.key = key;
	}

	public int compare(Map<String, String> o1, Map<String, String> o2) {
		String val1 = o1.get(key);
		String val2 = o2.get(key);
		try{
			Integer t1 = Integer.parseInt(val1);
			Integer t2 = Integer.parseInt(val2);
			if (t1 > t2) {
				return 1;
			} else if (t1 < t2) {
				return -1;
			} else {
				return 0;
			}
		}catch(Exception ex){
			return val1.compareTo(val2);
		}
	}
	
}
